var app = getApp()
Page({
  data: {
    userInfo: {},
    motto: 'Hello World',
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    hasUserInfo: false,
    // orderItems
    orderItems: [
      {
        typeId: 0,
        name: '待付款',
        url: 'bill',
        imageurl: '../../images/waitpay.png',
      },
      {
        typeId: 1,
        name: '待发货',
        url: 'bill',
        imageurl: '../../images/waitfahao.png',
      },
      {
        typeId: 2,
        name: '待收货',
        url: 'bill',
        imageurl: '../../images/waitshouhao.png'
      },
      {
        typeId: 3,
        name: '待评价',
        url: 'bill',
        imageurl: '../../images/waitpinjia.png'
      }
    ],
  },
  //事件处理函数
  toOrder: function () {
    wx.navigateTo({
      url: '../order/order'
    })
  },
  onLoad: function () {
    
  },

  onShow:function(){
    //if为真表示已经授过权
    console.log(app.globalData.userInfo);
    if (app.globalData.userInfo) {
      //console.log("11111");
      //console.log(app.globalData.userInfo);
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      });

    }
    else {      // 在没有 open-type=getUserInfo 版本的兼容处理
      //console.log("3333333")
      wx.navigateTo({
        url: '../login/login',
      })
      //弹出授权框，引导用户授权
     /* wx.showModal({
        title: '授权请求',
        content: '程序请求获取你的用户、头像等信息。是否同意获取？',
        showCancel: true,
        confirmText: '同意获取',
        success(res) {
          if (res.confirm) {
            console.log('用户点击确定')
            wx.navigateTo({
              url: '../login/login',
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
            that.setData({
              motto: "用户没有授权"
            })
          }
        }

      }) */

    }
  },


  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }

     
})
